﻿namespace ExcelExport
{
    public class TableField
    {
        public const string BYTE = "byte";
        public const string SHORT = "short";
        public const string INT = "int";
        public const string FLOAT = "float";
        public const string BOOL = "bool";
        public const string STRING = "string";
        public const string ULONG = "ulong";

        public TableType fieldType;
        public string strFieldType = "";

        public string filedName = "";
        public string explainStr = "";//注释

        public int colInx = 1;
        public bool isList = false;

        public void SetFieldType(string strFieldType)
        {
            if (string.IsNullOrEmpty(strFieldType))
                return;
            strFieldType = strFieldType.Trim();
            string listType = string.Empty;

            if ((strFieldType.EndsWith("[]")))
            {
                listType = strFieldType.Replace("[]", "");
            }
            isList = !string.IsNullOrEmpty(listType);
            string typeStr = string.IsNullOrEmpty(listType) ? strFieldType : listType;
            switch (typeStr)
            {
                case BYTE:
                    fieldType = TableType.BYTE;
                    this.strFieldType = BYTE;
                    break;
                case SHORT:
                    fieldType = TableType.SHORT;
                    this.strFieldType = SHORT;
                    break;
                case INT:
                    fieldType = TableType.INT;
                    this.strFieldType = INT;
                    break;
                case FLOAT:
                    fieldType = TableType.FLOAT;
                    this.strFieldType = FLOAT;
                    break;
                case BOOL:
                    fieldType = TableType.BOOL;
                    this.strFieldType = BOOL;
                    break;
                case STRING:
                    fieldType = TableType.STRING;
                    this.strFieldType = STRING;
                    break;
                case ULONG:
                    fieldType = TableType.ULONG;
                    this.strFieldType = ULONG;
                    break;
                default:
                    throw new Exception(string.Format("SetFieldType= {0} 类型错误", strFieldType));
            }
        }
    }

    public enum TableType
    {
        NULL,
        BYTE,
        SHORT,
        INT,
        FLOAT,
        BOOL,
        STRING,
        ULONG,
    }
}
